/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.user.controller.model.vo;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.siufung.core.model.AbstractVo;
import net.siufung.core.model.enums.DeletedEnum;
import net.siufung.core.model.enums.InitializeEnum;
import net.siufung.market.base.user.enums.UserSupers;

import java.time.LocalDateTime;

/**
 * @author 陈建峰
 * @since 2022-07-05 16:14:50
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="UserVo", description="系统用户表")
public class UserVo extends AbstractVo {

    private static final long serialVersionUID = -2066917683557344611L;
    /**
     * 主键ID
     */
    @ApiModelProperty(value = "主键ID")
    private Integer id;

    /**
     * 登录名
     */
    @ApiModelProperty(value = "登录名")
    private String loginName;

    /**
     * 登录密码
     */
    @ApiModelProperty(value = "登录密码")
    private String loginPwd;

    /**
     * 用户全称
     */
    @ApiModelProperty(value = "用户全称")
    private String userName;

    /**
     * 用户编码
     */
    @ApiModelProperty(value = "用户编码")
    private String userCode;

    /**
     * 初始化标识
     */
    @ApiModelProperty(value = "初始化标识")
    private Boolean initFlag;

    /**
     * 管理员级别
     */
    @ApiModelProperty(value = "管理员级别")
    private Boolean adminState;

    /**
     * 部门Id
     */
    @ApiModelProperty(value = "部门Id")
    private String deptId;

    /**
     * 部门名称
     */
    @ApiModelProperty(value = "部门名称")
    private String deptName;

    /**
     * 岗位Id
     */
    @ApiModelProperty(value = "岗位Id")
    private String postId;

    /**
     * 岗位名称
     */
    @ApiModelProperty(value = "岗位名称")
    private String postName;

    /**
     * 用户电话
     */
    @ApiModelProperty(value = "用户电话")
    private String mobile;

    /**
     * 身份证号码
     */
    @ApiModelProperty(value = "身份证号码")
    private String userIdCard;

    /**
     * 用户email
     */
    @ApiModelProperty(value = "用户email")
    private String email;

    /**
     * 用户性别
     */
    @ApiModelProperty(value = "用户性别")
    private String sex;

    /**
     * 用户头像
     */
    @ApiModelProperty(value = "用户头像")
    private String avatar;

    /**
     * 用户生日
     */
    @ApiModelProperty(value = "用户生日")
    private String birthday;

    /**
     * 用户描述
     */
    @ApiModelProperty(value = "用户描述")
    private String description;

    /**
     * 最后登录IP
     */
    @ApiModelProperty(value = "最后登录IP")
    private String loginLastIp;

    /**
     * 最后登录时间
     */
    @ApiModelProperty(value = "最后登录时间")
    private String loginLastDate;

    /**
     * 租户ID
     */
    @ApiModelProperty(value = "租户ID")
    private Integer tenantId;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String createdBy;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 更新人
     */
    @ApiModelProperty(value = "更新人")
    private String updatedBy;

    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime updatedAt;

    /**
     * 数据标识
     */
    @ApiModelProperty(value = "数据标识")
    private Boolean deleted;

    /**
     * 初始化状态描述
     * @return String
     */
    public String getInitFlagDesc(){
        return InitializeEnum.getDesc(initFlag);
    }

    /**
     * 管理员身份
     * @return String
     */
    public String getAdminStateDesc(){
        return UserSupers.getDesc(adminState);
    }


    @Override
    public String getDeletedDesc() {
        return DeletedEnum.getDesc(deleted);
    }

    @Override
    public boolean getAllowUpdate() {
        return DeletedEnum.NOT.equals(DeletedEnum.get(deleted)) &&
                UserSupers.NOT.equals(UserSupers.get(adminState));
    }

    @Override
    public boolean getAllowRemove() {
        return InitializeEnum.NOT.equals(InitializeEnum.get(initFlag)) &&
                UserSupers.NOT.equals(UserSupers.get(adminState));
    }

    @Override
    public boolean getAllowStatus() {
        return UserSupers.NOT.equals(UserSupers.get(adminState));
    }
}